Originally Posted by
Daved
That doesn't make sense. Can you post a simple, compilable example that demonstrates the problem? If T is completely unrelated to B, I don't see how x[0] can return a B.
Not sure if I got the psuedo in the original post correct, anyway, here's some code that dosn't compile:
Code:
#include <stdio.h>
template <typename T>
class A {
public:
char *operator[] (int);
};
template <typename T>
char *A<T>::operator[] (int i) {
char *test = new char;
*test = 'a';
return test;
}
class C {
/*...*/
};
class B : public A<C> {
};
int main() {
B *x;
char *y = x[0];
}
But if I change x[0] to (*x)[0] , then it compiles, go figure!